package com.hlkj.baojin.utils.bean;

import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component;

import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * @author lzx
 **/
@Component
public class Page implements Serializable, Pageable {

    private static final long serialVersionUID = 8854563067589233143L;

    /**
     * 当前页
     */
    @DecimalMin(value = "0",message = "公司类型错误")
    private Integer page;

    /**
     * 当前页面条数
     */
    @NotNull(message = "当前页面条数不能为空")
    private Integer size;

    /**
     * 排序条件
     */
    private Sort sort=new Sort(Sort.Direction.DESC, "qwedaqs");

    public Page() {
    }

    public Page(Integer page, Integer size) {
        this.page = page;
        this.size = size;
    }

    public void setSort(Sort sort) {
        this.sort = sort;
    }

    /**
     * // 当前页面
     *
     * @return
     */
    @Override
    public int getPageNumber() {
        return getPage();
    }

    /**
     * // 每一页显示的条数
     *
     * @return
     */
    @Override
    public int getPageSize() {
        return getSize();
    }

    /**
     * // 第二页所需要增加的数量
     *
     * @return
     */
    @Override
    public long getOffset() {
        return (getPage() - 1) * getSize();
    }

    @Override
    public Sort getSort() {
        return sort;
    }

    @Override
    public Pageable next() {
        return null;
    }

    @Override
    public Pageable previousOrFirst() {
        return null;
    }

    @Override
    public Pageable first() {
        return null;
    }

    @Override
    public boolean hasPrevious() {
        return false;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getSize() {
        return size;
    }

    public void setSize(Integer size) {
        this.size = size;
    }


}
